package com.rick.mr.numsort;


import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Random;


public class NumSortReducer extends Reducer<IntWritable, NullWritable, Text, NullWritable> {
    //1 重写reduce方法

    private final Text data = new Text();
    private int order = 0;

    @Override
    protected void reduce(IntWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {

        for (NullWritable value: values){
            order += 1;
            String new_key = order + "\t" + key;
            data.set(new_key);
            context.write(data, NullWritable.get());

//            data.set(order + "");
////            v.set();
//            context.write(data, key);
        }
    }
}
